package com.example.demo.controller;

import com.example.demo.pojo.User;
import com.example.demo.util.Md5Util;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class RegisterController {
    @RequestMapping("/register")
    public String showRegister(){
        return "register";
    }

    @RequestMapping("/userRegister")
    @ResponseBody
    public String userRegister(String userName,String password,String phone,String type){
        User user=new User();
        user.setUsername(userName);
        user.setPhone(phone);
        user.setPassword(Md5Util.MD5Encode(password+Md5Util.salt));
        user.setIdentity(type);
        System.out.println(user);


        try {
            registerService.userRegister(user);//返回1为成功
            return "success";
        }catch (Exception e){
            return "fail";
        }
    }
}
